<?php
if (! defined ( 'IN_BIC' )) {
	die ( '非法Exception访问来源!' );
}
/**
 *Bic_Exception自定义异常类
 * 在程序最后面有自定义错误及异常捕获
 * @package Bic
 * @author Bic
 * @version $Id: BicSqli.php 2010年5月11日 21时32分29秒
 * @copyright (c) 2010 Bic
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
 *
 * Minimum Requirement: PHP 5.0.1
 */
class Bic_Exception extends Exception {
    
    public function __construct($message,$code=null){
        parent::__construct($message,$code);
        //self::__debug($message,$code);
    }
    
    public function __toString(){
        return "<h3>BicPHP</h3><br/>exception '".__CLASS__ ."' with message '".$this->getMessage()."' in ".$this->getFile().":".$this->getLine()."\nStack trace:\n".$this->getTraceAsString();
    }
 
    
    /**
     * 自定义错误函数
     * @param type $errno
     * @param type $errstr
     * @param type $errfile
     * @param type $errline 
     */
    public static function errorHandle($errno, $errstr, $errfile, $errline) {
        switch ($errno) {
            case E_USER_ERROR:
                echo "<b>BicPHP ERROR</b> [$errno] $errstr<br />\n";
                echo "  Fatal error on line $errline in file $errfile";
                echo ", PHP " . PHP_VERSION . " (" . PHP_OS . ")<br />\n";
                echo "Aborting...<br />\n";
                exit(1);
                break;

            case E_USER_WARNING:
                echo "<b>BicPHP WARNING</b> [$errno] $errstr<br />\n";
                break;

            case E_USER_NOTICE:
                echo "<b>BicPHP NOTICE</b> [$errno] $errstr<br />\n";
                break;

            default:
                if (App::getDebugMode() == 'bicAll'){
                    echo "Unknown BicPHP error type: [$errno] $errstr at file $errfile line $errline<br />\n";
                }
                break;
        }
        return true;
    }
    
    /**
     *自定义顶级异常
     * @param type $e 
     */
    public static function exceptionHandle($e){
        echo '<pre>';
        echo $e;
    }

}
